<template>
	<view class="wrapper">
		<uni-nav-bar title="群组" backgroundColor="#f3f3f3" leftIcon='back' rightIcon='plusempty' @clickLeft='$back()' @clickRight="$open('../index/groupChat')">
		</uni-nav-bar>
		<dlContacts ref="jContacts" topHeight="80" :myList="pageData" :showBottom="false" :showRadio="false"></dlContacts>
		<alert alertTitle="回话" showInput="true" showCancel="false" @alertConfirm="alertConfirm" v-if="showAlert"></alert>
	</view>
</template>

<script>
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import WEBIM from '@/common/webim.js';
import dlContacts from '@/components/dl-contacts/dl-contacts.vue';
import alert from '../../components/alert/alert.vue';
export default {
	data() {
		return {
			showAlert: false,
			pageData: [],
			toUserId:'',
			toNickname:''
		};
	},
	onShow() {
		uni.removeStorageSync('newList')
		this.getList();
	},
	onLoad() {},
	methods: {
		friendsAdd(toUserId) {
			this.$ajax(this.apiList.friendsAdd, {
				toUserId: toUserId
			}).then(res => {
				this.$sToast('成功加为好友');
				this.getList();
			});
		},
		getList() {
			let that=this
			this.$ajax(
				this.apiList.roomList,
				{
					pageIndex: 0,
					pageSize: 100
				},
				'POST'
			).then(res => {
				this.pageData=[]
				res.data.forEach(item=>{
					item.toNickname=item.name,
					item.toUserId=item.userId
				})
				this.pageData = res.data
				setTimeout(function() {
					that.$refs.jContacts.show();
				}, 300);
			});
		},
		alertConfirm(type,text) {
			if(type==1){
				var msg = WEBIM.createMessage(1, text, this.toUserId, this.toNickname, 'chat');
				msg.id = msg.messageId;
				WEBIM.sendMessage(msg);
				this.$sToast('已回话')
			}
			this.changeAlert();
		},
		changeAlert(toUserId,toNickname) {
			this.toUserId=toUserId
			this.toNickname=toNickname
			this.showAlert = !this.showAlert;
		}
	},
	filters: {
		type(value, content) {
			if (value == 510) {
				return '已互为好友';
			} else if (value == 502||value==500) {
				return content;
			} else if (value == 505) {
				return '被取消了好友';
			}
		}
	},
	components: { alert,uniNavBar,dlContacts }
};
</script>

<style lang="scss">
dlContacts{
	top: 100rpx;
}
.user_box {
	padding: 19rpx 20rpx;
	.btn_box {
		.c666 {
			background: #e0e0e0;
			margin-left: 14rpx;
		}
		.cfff {
			background: #0297fe;
		}
		view {
			width: 160rpx;
			height: 65rpx;
			border-radius: 4rpx;
		}
	}
	.user_name {
		margin-bottom: 10rpx;
	}
	.avatar_box {
		width: 94rpx;
		height: 94rpx;
		border-radius: 50%;
		margin-right: 21rpx;
		overflow: hidden;
	}
}
</style>
